import DingTalkBasePublicService from "./BasePublicService";
import { Dingtalk } from "../dingtalk";
/**
 * todo
 * dingtalk
 * 身份验证
 * - sso 免登码获取用户信息等接口
 * - https://open.dingtalk.com/document/orgapp/obtain-the-userid-of-a-user-by-using-the-log-free
 */
export default class SsoService extends DingTalkBasePublicService {
	/**
	 *
	 * 通过免登码获取用户信息
	 * - https://open.dingtalk.com/document/orgapp/obtain-the-userid-of-a-user-by-using-the-log-free
	 *
	 * @param {string} code
	 * @memberof PlatformDingtalkBaseSsoService
	 */
	async getUserInfo(code: string) {
		const url = await this.getURL("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo");
		const data = {
			code,
		};
		const res = await this.curl<Dingtalk.sso.IResponseSSOGetUserInfo>(url, {
			contentType: "json",
			dataType: "json",
			method: "POST",
			data,
		});
		// @ts-ignore
		this.ovcheckError(url, res);
		return res.data;
	}
}
